<template>
    <!-- 维护作业-险种代码维护页面 -->
    <div class="fillcontain">
        <el-form :model="searchParams" :rules="rules" ref="ruleForm" label-width="100px" class="search_container">
            <el-row>
                <el-col :span="6">
                    <el-form-item label="险种代码" prop="crtable">
                        <el-input clearable v-model="searchParams.crtable" placeholder="险种代码"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="主附约" prop="stat_fund">
                        <el-select v-model="searchParams.stat_fund">
                            <el-option v-for="item in statFundType" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="保单类别" prop="cnttype">
                        <el-input clearable v-model="searchParams.cnttype" placeholder="保单类别"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="险种类别" prop="crtype">
                        <el-input clearable v-model="searchParams.crtype" placeholder="险种类别"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="需求代码" prop="srpisno">
                        <el-input clearable v-model="searchParams.srpisno" placeholder="需求代码"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6" class="text_center">
                    <el-button type="primary" icon="el-icon-search" @click="subGetList"></el-button>
                    <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
                </el-col>
            </el-row>
        </el-form>
        <div class="contain">
            <el-row class="bgfff pb15">
                <el-col :span="24" class="pt5">
                    <el-button type="danger" plain @click="addEufopky">新增</el-button>
                    <el-button type="danger" plain @click="exportEufopkyInfo">导出</el-button>
                </el-col>
            </el-row>
            <!-- 主档显示结果 -->
            <div class="table_container">
                <el-table v-loading="loading" :data="insCodetableData" @row-click="queryEufdenq" highlight-current-row header-cell-class-name="table-header-class"
                    style="width:100%">
                    <el-table-column min-width="120" property="crtable" label="险种代号" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="stat_fund" label="主附约" :formatter="statFund" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="cnttype" label="保单类别" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="acctype" label="保额累计类别" align='center' show-overflow-tooltip>
                        <template slot-scope="scope">
                            <span v-for="acct in acctypeEunm" v-if="scope.row.acctype == acct.value">{{acct.label}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column min-width="120" property="crunit" label="保额特殊规则" align='center' show-overflow-tooltip>
                        <template slot-scope="scope">
                            <span v-for="ifcr in crunitEunm" v-if="scope.row.crunit == ifcr.value">{{ifcr.label}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column min-width="120" property="wplnind" label="单位类别" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="200" property="planlmt" label="计算单位转换系数" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="cedprm" label="危险倍数" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="phy_exam_mult" label="体检件危险倍数" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="mortcls" label="职业等级" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="fromdate" label="销售起日" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="todate" label="销售止日" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="zpshortc" label="商品中文名称" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="crtype" label="险种类别" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="flag01" label="P/BT同主约" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="flag02" label="基金" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="flag03" label="取保单号" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="flag04" label="提前生效" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="flag05" label="F5" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="flag06" label="F6" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="pncode" label="加费照会" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="srpisno" label="需求代码" align='center' show-overflow-tooltip>
                    </el-table-column>
                    <el-table-column min-width="120" property="update_ind" label="更新方式" align='center' show-overflow-tooltip>
                        <template slot-scope="scope">
                            <span v-for="updateind in updateIndEunm" v-if="scope.row.update_ind == updateind.value">{{updateind.label}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column min-width="120" fixed="right" label="操作" align='center'>
                        <template slot-scope="scope">
                            <!-- <el-button type="text" size="small" @click="mianUpdateGo(scope.row)">修改</el-button> -->

                            <span class="operationIcon" @click="mianUpdateGo(scope.row)">
                                <el-tooltip class="item" effect="light" content="修改" placement="top">
                                    <i class="el-icon-edit"></i>
                                </el-tooltip>
                            </span>

                            <!-- <el-button type="text" size="small" @click="deleteEufopkyInfo(scope.row)">删除</el-button> -->
                            <span class="operationIcon ml5" @click="deleteEufopkyInfo(scope.row)">
                                <el-tooltip class="item" effect="light" content="删除" placement="top">
                                    <i class="el-icon-delete"></i>
                                </el-tooltip>
                            </span>

                        </template>
                    </el-table-column>
                </el-table>
                <el-row>
                    <el-col :span="24">
                        <div class="pagination">
                            <el-pagination background v-if='paginations1.total > 0' :page-sizes="paginations1.pageSizes" :page-size="paginations1.pageSize"
                                :layout="paginations1.layout" :total="paginations1.total" :current-page='paginations1.pageIndex'
                                @current-change='handleCurrentChange1' @size-change='handleSizeChange1'>
                            </el-pagination>
                        </div>
                    </el-col>
                </el-row>
            </div>

            <!-- 附档显示结果 -->
            <div class="table_container mt20">
                <el-row class="bgfff pb15">
                    <el-col :span="24" class="pt5">
                        <el-button type="danger" plain @click="addEufdenq">新增</el-button>
                        <el-button type="danger" plain @click="exportEufdenqInfo">导出</el-button>
                    </el-col>
                </el-row>
                <el-table v-loading="loading" :data="attachedtableData" highlight-current-row header-cell-class-name="table-header-class"
                    style="width:100%">
                    <el-table-column min-width="120" property="polpln" label="险种名称" align='center'>
                    </el-table-column>
                    <el-table-column min-width="120" property="crtable" label="险种代号" align='center'>
                    </el-table-column>
                    <el-table-column min-width="120" property="prmsw" label="缴费别" align='center'>
                        <template slot-scope="scope">
                            <span v-for="prmsw in prmswEunm" v-if="scope.row.prmsw == prmsw.value">{{prmsw.label}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column min-width="120" property="prem_cess_term" label="缴费期间" align='center'>
                    </el-table-column>
                    <el-table-column min-width="120" property="rsk_sw" :formatter="ifprmsw" label="保障别" align='center'>
                        <template slot-scope="scope">
                            <span v-for="prm in prmswEunm" v-if="scope.row.rsk_sw == prm.value">{{prm.label}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column min-width="120" property="risk_cess_term" label="保障时间" align='center'>
                    </el-table-column>
                    <el-table-column min-width="120" property="srpisno" label="需求代码" align='center'>
                    </el-table-column>
                    <el-table-column min-width="120" property="update_ind" label="更新方式" align='center'>
                        <template slot-scope="scope">
                            <span v-for="updateind in updateIndEunm" v-if="scope.row.update_ind == updateind.value">{{updateind.label}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column min-width="120" label="操作" align='center'>
                        <template slot-scope="scope">
                            <!-- <el-button type="text" size="small" @click="attachedUpdateGo(scope.row)">修改</el-button> -->
                            <span class="operationIcon" @click="attachedUpdateGo(scope.row)">
                                <el-tooltip class="item" effect="light" content="修改" placement="top">
                                    <i class="el-icon-edit"></i>
                                </el-tooltip>
                            </span>

                            <!-- <el-button type="text" size="small" @click="deleteEufdenqInfo(scope.row)">删除</el-button> -->
                            <span class="operationIcon ml5" @click="deleteEufdenqInfo(scope.row)">
                                <el-tooltip class="item" effect="light" content="删除" placement="top">
                                    <i class="el-icon-delete"></i>
                                </el-tooltip>
                            </span>

                        </template>
                    </el-table-column>
                </el-table>
                <el-row>
                    <el-col :span="24">
                        <div class="pagination">
                            <el-pagination background v-if='paginations2.total > 0' :page-sizes="paginations2.pageSizes" :page-size="paginations2.pageSize"
                                :layout="paginations2.layout" :total="paginations2.total" :current-page='paginations2.pageIndex'
                                @current-change='handleCurrentChange2' @size-change='handleSizeChange2'>
                            </el-pagination>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </div>
        <!-- 弹框 主档修改-->
        <el-dialog title="险种代码主表维护" :visible.sync="mainDialog" width="60%" center>
            <el-form ref="form" label-width="120px">
                <el-row>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">险种代码</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input placeholder="" v-if="update" disabled v-model="eufopkyDetail.crtable"></el-input>
                            <el-input clearable placeholder="" v-else v-model="eufopkyDetail.crtable" @blur='checkCrtableInfo("2",eufopkyDetail.crtable)'></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">主附约</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufopkyDetail.stat_fund" placeholder="">
                                <el-option v-for="item in statFundType" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">保单类别</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.cnttype"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">保额累计类别</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufopkyDetail.acctype" placeholder="">
                                <el-option v-for="item in acctypeEunm" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">保额特殊规则</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufopkyDetail.crunit" placeholder="">
                                <el-option v-for="item in crunitEunm" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">单位类别</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufopkyDetail.wplnind" placeholder="">
                                <el-option v-for="item in wplnindEunm" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">计算单位<br/>转换系数</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.planlmt"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">危险倍数</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.cedprm"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">体检危险倍数</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.phy_exam_mult"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">职业等级</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufopkyDetail.mortcls" placeholder="">
                                <el-option v-for="item in mortclsType" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">销售起日</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.fromdate"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">销售止日</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.todate"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">商品中文名称</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.zpshortc"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">险种类别</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.crtype"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">P/BT同主约</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.flag01"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">基金</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.flag02"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">取保单号</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.flag03"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">提前生效</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.flag04"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">F5</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.flag05"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">F6</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.flag06"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">加费照会</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.pncode"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">需求代码</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.srpisno" @blur="checkSrpisnoInfo('1',eufopkyDetail.srpisno)"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">更新方式</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufopkyDetail.update_ind" placeholder="">
                                <el-option v-for="item in updateIndEunm" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">是否重疾<br/>按寿险加费</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufopkyDetail.raflag01" placeholder="">
                                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">除外照会</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufopkyDetail.butpncode"></el-input>
                        </el-col>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="saveEufopky" class="Defaultbutton">保 存</el-button>
                <el-button @click="mainDialog = false">返 回</el-button>
            </span>
        </el-dialog>

        <!-- 弹框 附档修改-->
        <el-dialog title="险种代码附表维护" :visible.sync="attachedDialog" width="60%" center>
            <el-form ref="form" label-width="120px">
                <el-row>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">险种名称</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" maxlength="10" v-model="eufdenqDetail.polpln" @blur='checkCrtableInfo("1",eufdenqDetail.polpln)'></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">险种代码</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" disabled v-model="eufdenqDetail.crtable"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">缴费别</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufdenqDetail.prmsw" placeholder="">
                                <el-option v-for="item in prmswEunm" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">缴费期间</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufdenqDetail.prem_cess_term"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">保障别</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufdenqDetail.rsk_sw" placeholder="">
                                <el-option v-for="item in prmswEunm" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">保障期间</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufdenqDetail.risk_cess_term"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">需求代码</label>
                        </el-col>
                        <el-col :span="16">
                            <el-input clearable placeholder="" v-model="eufdenqDetail.srpisno" @blur="checkSrpisnoInfo('2',eufdenqDetail.srpisno)"></el-input>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">更新方式</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="eufdenqDetail.update_ind" placeholder="">
                                <el-option v-for="item in updateIndEunm" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                            <label class="labelName">是否重疾<br/>按寿险加费</label>
                        </el-col>
                        <el-col :span="16">
                            <el-select v-model="options" placeholder="">
                                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="saveEufdenq" class="Defaultbutton">保 存</el-button>
                <el-button @click="attachedDialog = false">返 回</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
    import { mapState, mapGetters } from 'vuex'
    import constant from '@/utils/constant';
    import appName from "@/api/appName.js";
    import axios from 'axios';
    import { getToken, setToken } from '@/utils/auth'
    import { checkSrpisno } from "@/api/setting/replyCodeMaintenance.js";
    import maintainConstants from '@/utils/maintainConstants';
    import { getKindInfoList, selectEufdenqList, modifyKind, modifyEufdenqInfo, deleteEufopky, deleteEufdenq, exportEufopky, exportEufdenq, checkCrtable } from '@/api/setting/maintain/kindUphold.js';
    export default {
        data() {
            return {
                mainDialog: false,//默认隐藏 险种代码维护主表修改弹框
                attachedDialog: false,//默认隐藏 险种代码维护附表修改弹框
                update: false,
                checkSrpisnoFlag: false,
                // 查询条件
                rules: {
                    customerNo: [],
                    customerName: [],
                    idNo: [],
                },
                searchParams: {
                    crtable: '',
                    stat_fund: '',
                    cnttype: '',
                    crtype: '',
                    srpisno: '',
                },
                insCodetableData: [//主档数据

                ],
                attachedtableData: [//附档数据
                ],
                loading: false,

                form: [//主档弹框表单
                    {
                        customerName: '',
                    }
                ],
                option: '',
                options: [
                    { value: '1', label: '是' },
                    { value: '2', label: '否' }
                ],
                statFundType: [
                    { value: 'M', label: '主约' },
                    { value: 'R', label: '附约' }
                ],
                mortclsType: [
                    { value: 'Y', label: 'Y' },
                    { value: 'N', label: 'N' }
                ],
                acctypeEunm: maintainConstants.acctypeEunm,
                crunitEunm: maintainConstants.crunitEunm,
                updateIndEunm: maintainConstants.updateIndEunm,
                prmswEunm: maintainConstants.prmswEunm,
                wplnindEunm: maintainConstants.wplnindEunm,
                eufopkyDetail: {},
                eufdenqDetail: {},
                add: false,
                crtable: '',
                flagForCrtable: '',
                //需要给分页组件传的信息
                paginations1: {
                    total: 0,        // 总数
                    pageIndex: 1,  // 当前位于哪页
                    pageSize: 10,   // 1页显示多少条
                    pageSizes: [5, 10, 15, 20],  //每页显示多少条
                    layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
                },
                paginations2: {
                    total: 0,        // 总数
                    pageIndex: 1,  // 当前位于哪页
                    pageSize: 10,   // 1页显示多少条
                    pageSizes: [5, 10, 15, 20],  //每页显示多少条
                    layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
                },
                pickerOptions1: {
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    }
                }
            }
        },
        mounted() {
            // this.getList();
        },
        methods: {
            //检查需求号是否存在
            checkSrpisnoInfo(type, item) {
                let para = {
                    "srpisno": item
                }
                checkSrpisno(para).then(res => {
                    if (res.resultCode == constant.SUCCESS) {
                        if (res.data == 0) {
                            this.popMsg("需求号码必须存在且尚未结案!", "error");
                            this.checkSrpisnoFlag = true;
                            if (type == "1") {
                                this.eufopkyDetail.srpisno = "";
                            } else if (type == "2") {
                                this.eufdenqDetail.srpisno = "";
                            }

                        } else {
                            console.log(res)
                            this.checkSrpisnoFlag = false;
                        }
                    } else {
                        this.popMsg("需求号码必须存在且尚未结案!", "error");
                        this.checkSrpisnoFlag = false;
                    }
                }).catch(err => {
                    this.popMsg("需求号码必须存在且尚未结案!", "error");
                    this.checkSrpisnoFlag = false;
                })
            },
            //检验险种代码是否存在
            checkCrtableInfo(type, item) {
                let CHNReg = /[\u4e00-\u9fa5]/;//汉字的正则表达式
                let Reg = new RegExp(CHNReg);
                if (type == "1") {
                    if (Reg.test(item)) {
                        this.popMsg("险种名称不能为汉字", "error")
                        return false;
                    }
                } else if (type == "2") {
                    if (Reg.test(item)) {
                        this.popMsg("险种代码不能为汉字", "error")
                        return false;
                    }
                }
                let objValue = item;
                item = objValue.toUpperCase();
                if (type == "1") {
                    this.eufdenqDetail.polpln = item;
                } else if (type == "2") {
                    this.eufopkyDetail.crtable = item;
                }

                checkCrtable(item).then(res => {
                    if (res.resultCode == constant.SUCCESS) {
                        if (res.data > 0) {
                            this.flagForCrtable = "no";
                        } else {
                            this.flagForCrtable = "yes";
                        }
                    }
                }).catch(err => {

                })
            },
            //主表编辑
            mianUpdateGo(row) {
                this.eufopkyDetail = row;
                this.mainDialog = true;
                this.update = true;
                this.checkSrpisnoFlag = false;
            },
            attachedUpdateGo(row) {
                this.eufdenqDetail = row;
                this.eufdenqDetail.polpln = this.eufdenqDetail.polpln.trim();
                this.attachedDialog = true;
                this.eufdenqDetail['oper'] = "edit";
                this.eufdenqDetail['polpln_old'] = this.eufdenqDetail.polpln;
                this.checkSrpisnoFlag = false;
            },
            //主表新增
            addEufopky() {
                this.eufopkyDetail = {}
                this.mainDialog = true;
                this.update = false;
            },
            //附表新增
            addEufdenq() {
                this.eufdenqDetail = {};
                this.eufdenqDetail.crtable = this.crtable;
                this.eufdenqDetail['oper'] = "add";
                this.attachedDialog = true;
            },
            //主表导出
            exportEufopkyInfo() {
                let url = appName.PRODUCT + '/uphold/kinduphold/exportEufopky';
                this.$store.dispatch('loading/CHANGE_LOADING', true);
                axios.get(url, {
                    responseType: 'arraybuffer', // 或者responseType: 'blob'
                    xsrfHeaderName: 'Authorization',
                    headers: {
                        'Authorization': getToken(constant.TOKEN) || ''
                    }
                }).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING', false);
                    const blob = new Blob([res.data], {
                        type: 'application/vnd.ms-excel;charset=utf-8'
                    })
                    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                        window.navigator.msSaveOrOpenBlob(blob, 'kindUpholdFile.xls');
                    }
                    const objectUrl = URL.createObjectURL(blob);

                    const eleLink = document.createElement('a')
                    eleLink.download = 'kindUpholdFile.xls'
                    eleLink.style.display = 'none'
                    eleLink.href = objectUrl
                    // 触发点击
                    document.body.appendChild(eleLink)
                    eleLink.click()
                    // 然后移除
                    document.body.removeChild(eleLink)
                }).catch(err => {
                    console.log(err)
                })
            },
            //附表导出
            exportEufdenqInfo() {
                let url = appName.PRODUCT + '/uphold/kinduphold/exportEufdenq';
                this.$store.dispatch('loading/CHANGE_LOADING', true);
                axios.get(url, {
                    responseType: 'arraybuffer', // 或者responseType: 'blob'
                    xsrfHeaderName: 'Authorization',
                    headers: {
                        'Authorization': getToken(constant.TOKEN) || ''
                    }
                }).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING', false);
                    console.log("daochu11111" + res.data)
                    const blob = new Blob([res.data], {
                        type: 'application/vnd.ms-excel;charset=utf-8'
                    })
                    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                        console.log("daochu222222" + blob)
                        window.navigator.msSaveOrOpenBlob(blob, 'eufdenqFile.xls');
                    }
                    const objectUrl = URL.createObjectURL(blob);

                    const eleLink = document.createElement('a')
                    eleLink.download = 'eufdenqFile.xls'
                    eleLink.style.display = 'none'
                    eleLink.href = objectUrl
                    // 触发点击
                    document.body.appendChild(eleLink)
                    eleLink.click()
                    // 然后移除
                    document.body.removeChild(eleLink)
                }).catch(err => {
                    console.log(err)
                })

            },
            //主表信息保存
            saveEufopky() {
                if (this.eufopkyDetail.crtable == null || this.eufopkyDetail.crtable == "") {
                    this.popMsg("请输入险种代码!", "error");
                    return;
                }
                if (this.checkSrpisnoFlag) {
                    this.popMsg("需求号码必须存在且尚未结案!", "error");
                    return;
                }
                if (this.flagForCrtable == "yes") {
                    this.popMsg("输入的险种代码在MI Product中没有设置!", "error");
                    return;
                }
                if (this.eufopkyDetail.srpisno == null || this.eufopkyDetail.srpisno == "") {
                    this.popMsg("请输入需求号码!", "error");
                    return;
                }
                if (this.eufopkyDetail.planlmt == null || this.eufopkyDetail.planlmt == "") {
                    this.popMsg("请输入计算单位转换系数!", "error");
                    return;
                }
                if (this.eufopkyDetail.cedprm == null || this.eufopkyDetail.cedprm == "") {
                    this.popMsg("请输入危险倍数!", "error");
                    return;
                }
                if (this.eufopkyDetail.phy_exam_mult == null || this.eufopkyDetail.phy_exam_mult == "") {
                    this.popMsg("请输入体检件危险倍数!", "error");
                    return;
                }
                if (this.eufopkyDetail.fromdate == null || this.eufopkyDetail.fromdate == "") {
                    this.popMsg("请输入销售起日!", "error");
                    return;
                }
                if (this.eufopkyDetail.todate == null || this.eufopkyDetail.todate == "") {
                    this.popMsg("请输入销售止日!", "error");
                    return;
                }
                if (!/^[a-zA-Z0-9]+$/.test(this.eufopkyDetail.crtable)) {
                    this.popMsg("险种代码只能输入字母/数字!", "error");
                    return;
                }
                //验证是否为汉字
                if (this.checkLegal(this.eufopkyDetail.crtable, "险种代码不能为汉字") || this.checkLegal(this.eufopkyDetail.srpisno, "需求号码不能为汉字")) {
                    return;
                }
                //验证是否为整数
                if (this.checkNumisInteger(this.eufopkyDetail.planlmt, "计算单位转换系数只能为整数") || this.checkNumisInteger(this.eufopkyDetail.fromdate, "销售起日只能为整数") || this.checkNumisInteger(this.eufopkyDetail.todate, "销售止日只能为整数")) {
                    return;
                }
                //验证是否为合法数字
                if (this.checkMaxNum(this.eufopkyDetail.cedprm, 99999999.99, "危险倍数的绝对值只能小于或等于99999999.99") || this.checkMaxNum(this.eufopkyDetail.phy_exam_mult, 999.99, "体检件危险倍数的绝对值只能小于或等于999.99")) {
                    return;
                }
                this.$store.dispatch('loading/CHNAGE_SUBLOADING', true)
                modifyKind(this.eufopkyDetail).then(res => {
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING', false)
                    if (res.resultCode == constant.SUCCESS) {
                        this.popMsg("保存成功!", "success");
                        this.mainDialog = false;
                        this.searchParams.crtable = this.eufopkyDetail.crtable;
                        this.getList();

                    }
                }).catch(err => {
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING', false)
                })

            },
            //附表信息保存
            saveEufdenq() {
                if (this.eufdenqDetail.polpln == null || this.eufdenqDetail.polpln == "") {
                    this.popMsg("请输入险种名称!", "error");
                    return;
                } else {
                    if (!/^[a-zA-Z0-9]+$/.test(this.eufdenqDetail.polpln)) {
                        this.popMsg("险种名称只能输入字母/数字!", "error");
                        return;
                    }
                }
                if (this.eufdenqDetail.prem_cess_term == null || this.eufdenqDetail.prem_cess_term == "") {
                    this.popMsg("请输入缴费期间!", "error");
                    return;
                }
                if (this.eufdenqDetail.risk_cess_term == null || this.eufdenqDetail.risk_cess_term == "") {
                    this.popMsg("请输入保障期间!", "error");
                    return;
                }
                if (this.eufdenqDetail.srpisno == null || this.eufdenqDetail.srpisno == "") {
                    this.popMsg("请输入需求号码!", "error");
                    return;
                }
                //验证是否为数字
                if (this.checkNum(this.eufdenqDetail.prem_cess_term, "缴费期间只能为数字") || this.checkNum(this.eufdenqDetail.risk_cess_term, "保障期间只能为数字")) {
                    return;
                }
                //验证是否为汉字
                if (this.checkLegal(this.eufdenqDetail.polpln, "险种名称不能为汉字") || this.checkLegal(this.eufdenqDetail.srpisno, "需求号码不能为汉字")) {
                    return;
                }
                //验证数字是否合法
                if (this.checkNeededNum(this.eufdenqDetail.prem_cess_term, "缴费期间只能为大于1小于99的整数") || this.checkNeededNum(this.eufdenqDetail.risk_cess_term, "保障期间只能为大于1小于99的整数")) {
                    return;
                }
                this.$store.dispatch('loading/CHNAGE_SUBLOADING', true)
                modifyEufdenqInfo(this.eufdenqDetail).then(res => {
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING', false)
                    if (res.resultCode == constant.SUCCESS) {
                        this.popMsg("保存成功!", "success");
                        this.attachedDialog = false;
                        let paras = {
                            "crtable": this.eufdenqDetail.crtable
                        }
                        this.queryEufdenq(paras);
                    }
                }).catch(err => {
                    this.$store.dispatch('loading/CHNAGE_SUBLOADING', false)
                })

            },
            // 查询列表
            getList() {
                this.paginations1.total = 0;
                let para = {
                    "crtable": this.searchParams.crtable,
                    "stat_fund": this.searchParams.stat_fund,
                    "cnttype": this.searchParams.cnttype,
                    "crtype": this.searchParams.crtype,
                    "srpisno": this.searchParams.srpisno,
                    "pageSize": this.paginations1.pageSize,
                    "pageNumber": this.paginations1.pageIndex,
                }
                this.$store.dispatch('loading/CHANGE_LOADING', true)
                getKindInfoList(para).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING', false)
                    if (res.resultCode == constant.SUCCESS) {
                        if (res.data) {
                            this.paginations1.total = res.data.total;
                            this.insCodetableData = res.data.list;
                        } else {
                            this.insCodetableData = [];
                            this.attachedtableData = [];
                            this.popMsg(res.resultMsg, "error");
                        }
                    }

                }).catch(err => {
                    this.$store.dispatch('loading/CHANGE_LOADING', false);
                })
            },
            //附表查询
            queryEufdenq(item) {
                this.crtable = item.crtable;
                let para = {
                    "crtable": this.crtable,
                    "pageSize": this.paginations2.pageSize,
                    "pageNumber": this.paginations2.pageIndex,
                }
                this.$store.dispatch('loading/CHANGE_LOADING', true)
                selectEufdenqList(para).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING', false)
                    if (res.resultCode == constant.SUCCESS) {
                        if (res.data) {
                            this.paginations2.total = res.data.total;
                            this.attachedtableData = res.data.list;
                        } else {
                            this.attachedtableData = [];
                        }

                    }

                }).catch(err => {
                    this.$store.dispatch('loading/CHANGE_LOADING', false);
                })
            },
            //主表删除
            deleteEufopkyInfo(row) {
                this.queryEufdenq(row);
                let title = "确定要删除险种:" + row.crtable + "   吗？"
                if (this.attachedtableData.length > 0) {
                    title = '其下有子项确定是否删除！'
                }
                this.$confirm(title, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$store.dispatch('loading/CHANGE_LOADING', true)
                    deleteEufopky(row).then(res => {
                        this.$store.dispatch('loading/CHANGE_LOADING', false)
                        if (res.resultCode == constant.SUCCESS) {
                            this.getList();
                            this.queryEufdenq('');
                        }

                    }).catch(err => {
                        this.$store.dispatch('loading/CHANGE_LOADING', false);
                    })
                }).catch(() => {

                });

            },
            //附表删除
            deleteEufdenqInfo(row) {
                let title = "确定要删除险种:" + row.polpln + "吗？";
                this.$confirm(title, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$store.dispatch('loading/CHANGE_LOADING', true)
                    deleteEufdenq(row).then(res => {
                        this.$store.dispatch('loading/CHANGE_LOADING', false)
                        if (res.resultCode == constant.SUCCESS) {
                            this.popMsg("删除成功!", "success");
                            let info = {};
                            info.crtable = this.crtable;
                            this.queryEufdenq(info);
                        }

                    }).catch(err => {
                        this.$store.dispatch('loading/CHANGE_LOADING', false);
                    })
                }).catch(() => {

                });



            },



            // 每页多少条切换
            handleSizeChange1(pageSize) {
                this.paginations1.pageSize = pageSize;
                this.getList();
            },
            handleSizeChange2(pageSize) {
                this.paginations2.pageSize = pageSize;
                let eufd = {};
                eufd.crtable = this.crtable;
                this.queryEufdenq(eufd);
            },
            // 上下分页
            handleCurrentChange1(page) {
                this.paginations1.pageIndex = page;
                this.getList();
            },
            handleCurrentChange2(page) {
                this.paginations2.pageIndex = page;
                let eufd = {};
                eufd.crtable = this.crtable;
                this.queryEufdenq(eufd);
            },
            // 根据条件查询列表
            subGetList() {
                this.paginations1.pageIndex = 1;
                this.getList();
            },
            // 清除查询条件
            resetSearch() {
                this.searchParams.crtable = '';
                this.searchParams.stat_fund = '';
                this.searchParams.cnttype = '';
                this.searchParams.crtype = '';
                this.searchParams.srpisno = '';
            },
            ifacctype(val) {
                if (val.acctype == this.acctypeEunm.value) { return this.acctypeEunm.label }
            },
            statFund(val) {
                if (val.stat_fund == 'M') { return '主约' }
                if (val.stat_fund == 'R') { return '附约' }
            },
            ifcrunit(val) {
                if (val.crunit == this.crunitEunm.value) { return this.crunitEunm.label }
            },
            ifupdateInd(val) {
                if (val.update_ind == this.updateIndEunm.value) { return this.updateIndEunm.label }
            },
            ifprmsw(val) {
                if (val.prmsw == this.prmswEunm.value) { return this.prmswEunm.label }
            },
            //验证是否为汉字
            checkLegal(obj, msg) {
                let CHNReg = /[\u4e00-\u9fa5]/;//汉字的正则表达式
                let Reg = new RegExp(CHNReg);
                if (Reg.test(obj)) {
                    this.popMsg(msg, "error");
                    obj.focus();
                    return true;
                }
            },
            //验证是否为数字
            checkNum(obj, msg) {
                if (isNaN(obj) || obj == "") {
                    this.popMsg(msg, "error");
                    return true;
                }
            },
            checkMaxNum(obj, max, msg) {
                if (isNaN(obj) || obj == "") {
                    this.popMsg(msg, "error");
                    return true;
                } else {
                    if (obj > max) {
                        this.popMsg(msg, "error");
                        return true;
                    }
                }
            },
            //验证输入的数字是否合法
            checkNeededNum(obj, msg) {
                let num = new Number(obj);
                if (num % 1 != 0 || num < 1 || num > 99) {
                    this.popMsg(msg, "error");
                    return true;
                }
            },
            //验证输入的数字是否整数
            checkNumisInteger(obj, msg) {
                let num = new Number(obj);
                if (num % 1 != 0 || num < 1) {
                    this.popMsg(msg, "error");
                    return true;
                }
            },
            popMsg(message, type) {
                this.$message({
                    message: message,
                    type: type
                });
            },
        },

        computed: {
            ...mapGetters(['tags']),
            reload() {
                return this.$store.state.loading.reload;
            }
        },
        activated() {
            if (this.reload) {
                this.$store.dispatch('loading/CHNAGE_RELOAD', false)
                Object.assign(this.$data, this.$options.data());
            }
        }
    }

</script>

<style lang="less" scoped>
    .fillcontain {
        padding-bottom: 0;
    }

    .contain {
        background: #fff;
        padding: 10px;
        margin-bottom: 20px;
    }

    .pagination {
        padding: 10px 20px;
        text-align: right;
    }

    .operationIcon {
        // padding: 12px;
        border: 1px solid #e5e5e5;
        border-radius: 50%;
        width: 22px;
        height: 22px;
        display: inline-block;
        cursor: pointer;
        box-shadow: 0 0 3px #f9f9f9;
    }

    .search_container {
        padding: 20px 20px 0 20px; //    border-top: 1px solid #e1e1e1;
    }

    .common-box {
        padding-bottom: 15px;
    }

    .common-lab {
        line-height: normal!important;
        text-align: right;
        .labelName {
            text-align: right;
        }
    }
</style>